/**
 * 线程间通信 worker
 */
import worker from '@ohos.worker'
import hilog from '@ohos.hilog'

let parent = worker.workerPort

let TAG: string = "worker-task"

// 处理来自主线程的消息
parent.onmessage = function (message) {
  hilog.info(0x1002, TAG, "worker thread onmessage:" + JSON.stringify(message))

  // 发送消息到主线程
  setTimeout(() => {
    parent.postMessage("message from worker thread!")
  }, 2000)

}